//
//  KYCityWeatherVC-UI.swift
//  ZhiYunWeather
//
//  Created by Wade on 2024/7/10.
//

import Foundation
import UIKit
import QMUIKit
extension KEAlphabet{
    func setupSubViews(){
        let contentView = UIView()
        self.view.addSubview(contentView)
        contentView.snp.makeConstraints { make in
            make.top.equalTo(self.view.safeAreaLayoutGuide.snp.top)
            make.left.right.bottom.equalTo(self.view)
        }
        
        let backBtn = UIButton()
        backBtn.setImage(.init(named: "ic_close"), for: .normal)
        contentView.addSubview(backBtn)
        backBtn.snp.makeConstraints { make in
            make.width.height.equalTo(40)
            make.top.equalTo(contentView)
            make.left.equalTo(contentView).offset(10)
        }
        backBtn.addTarget(self, action: #selector(backBtnClick), for: .touchUpInside)
        
        let startGameBtn = UIButton()
        startGameBtn.setImage(.init(named: "ic_start"), for: .normal)
        contentView.addSubview(startGameBtn)
        startGameBtn.snp.makeConstraints { make in
            make.width.height.equalTo(200)
            make.top.equalTo(backBtn.snp.bottom).offset(20)
            make.right.equalTo(contentView).offset(-50)
        }
        startGameBtn.addTarget(self, action: #selector(startGameBtnClick), for: .touchUpInside)
    
        let aBtn = UIButton()
//        aBtn.setImage(.init(named: self.content ?? "A"), for: .normal)
        aBtn.setTitle(self.content!+self.content!.lowercased(), for: .normal)
        aBtn.titleLabel?.font = .customFont(fontSize: 160)
        aBtn.setTitleColor(.highlightTextColor, for: .normal)
        aBtn.setTitleColor(.MainTextColor, for: .highlighted)
        contentView.addSubview(aBtn)
        aBtn.snp.makeConstraints { make in
            make.width.height.equalTo(200)
            make.top.equalTo(backBtn.snp.bottom).offset(20)
            make.centerX.equalTo(contentView)
        }
        aBtn.addTarget(self, action: #selector(aBtnClick), for: .touchUpInside)
        self.aBtn = aBtn
        
        // Create a waterfall layout
        let layout = UICollectionViewFlowLayout()
        layout.scrollDirection = .horizontal
        layout.itemSize = CGSizeMake(150, 200)
        layout.minimumLineSpacing = 20;
        
        var leftMargin = 10.0;
        if(self.menuList.count == 1){
            leftMargin = (Constant.kScreenWidth - 150) / 2
        }else  if(self.menuList.count == 2){
            leftMargin = Constant.kScreenWidth / 2 - 150
        }
        layout.sectionInset = UIEdgeInsets(top: 0, left: leftMargin, bottom: 0, right: 10)
        let collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: layout)
        contentView.addSubview(collectionView)
        collectionView.backgroundColor = .clear
        collectionView.snp.makeConstraints { make in
            make.left.right.equalTo(contentView)
            make.top.equalTo(aBtn.snp.bottom).offset(30)
            make.height.equalTo(210)
        }
        collectionView.delegate = self
        collectionView.dataSource = self
        self.collectionView = collectionView
        
        let tableView = UITableView()
        contentView.addSubview(tableView)
        tableView.delegate = self;
        tableView.dataSource = self;
        tableView.snp.makeConstraints { make in
            make.left.right.equalTo(contentView)
            make.top.equalTo(collectionView.snp.bottom).offset(30)
            make.height.equalTo(150)
        }
        self.tableView = tableView;
        
        
        let recordBtn = UIButton()
        recordBtn.setImage(.init(named: "ic_record"), for: .normal)
        contentView.addSubview(recordBtn)
        recordBtn.snp.makeConstraints { make in
            make.width.height.equalTo(80)
            make.top.equalTo(tableView.snp.bottom)
            make.centerX.equalTo(contentView)
        }
        recordBtn.addTarget(self, action: #selector(recordBtnClick), for: .touchUpInside)
    }
}
